package cn.wuqingna.legendgem.suit

import cn.wuqingna.legendgem.cache.PlayerManager
import cn.wuqingna.legendgem.loader.SuitLoader
import org.bukkit.Bukkit
import taboolib.common.platform.function.adaptPlayer
import taboolib.common.platform.function.submitAsync
import taboolib.common5.cbool
import taboolib.module.kether.KetherShell
import taboolib.module.kether.ScriptOptions
import java.util.UUID

object SuitManager {

    fun refreshSuit(uuid: UUID){
        val player = Bukkit.getPlayer(uuid) ?: return
        val map = SuitLoader.suit.filter {
            KetherShell.eval(it.value.conditions, ScriptOptions.new { sender(adaptPlayer(player)) }).get().cbool
        }
        val playerCache = PlayerManager.get(uuid)
        playerCache.suit = map.toMutableMap()
    }
    fun asynrefreshSuit(uuid: UUID){
        submitAsync {
            refreshSuit(uuid)
        }

    }


}